package com.wcl.demo.db;

import com.wcl.demo.model.entity.UserInfor;
import com.wcl.demo.model.entity.UserInforDao;

import java.util.List;

/**
 * Created by dllo on 15/11/23.
 */
public class UserInforHelper {
    private DaoSingleton instance = DaoSingleton.getInstance();
    private UserInforDao inforDao;

    public UserInforHelper() {
        this.inforDao = instance.getInforDao();
    }

    /***
     * 添加数据
     */

    public void saveUserInfor(List<UserInfor> infors) {
        inforDao.insertInTx(infors);
    }

    /***
     * 删除
     */
    public void deleteAll() {
        inforDao.deleteAll();
    }

    /***
     * 查询
     */
    public List<UserInfor> queryAll() {
        return inforDao.loadAll();
    }

    /***
     * 按用户名进行查询
     */
    public List<UserInfor> queryByUserName(String username) {
        List<UserInfor> list = inforDao.queryBuilder().where(UserInforDao.Properties.Username.eq(username)).list();
        return list;
    }

    /***
     * 更新用户信息
     *
     * @param infore
     */
    public void updateByUserName(UserInfor infore) {
        inforDao.update(infore);
    }
}
